﻿//    Copyright 2010,2011 Himanshu Vasishth
//   
//    This file is part of SecretVault.
//
//    SecretVault is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    SecretVault is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with SecretVault.  If not, see <http://www.gnu.org/licenses/>.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PasswordStoreProvider
{
    /// <summary>
    /// Responsible for storing and retreiving passwords. This class does not handle
    /// encryption/decryption of the password.
    /// </summary>
    public interface IVaultStore : IDisposable
    {
        /// <summary>
        /// Opens the password store at the specified url using the specified master password
        /// </summary>
        /// <exception cref="InvalidMasterPasswordException">
        /// If the master password is incorrect
        /// </exception>
        void Open(string masterPassword, string storeUrl);

        /// <summary>
        /// Changes the master password from the oldPassword to the newPassword
        /// </summary>
        /// <exception cref="InvalidMasterPasswordException">
        /// If the old masterPassword is incorrect
        /// </exception>
        void ChangeMasterPassword(string oldPassword, string newPassword);

        /// <summary>
        /// Returns the location where the store currently being used is located
        /// </summary>
        string StoreLocation { get; }

        /// <summary>
        /// Stores the specified LoginInfo with the specified password. The passed password is the actual
        /// password and should ideally be encrypted before being stored. 
        /// If the LoginInfo object alreay exists in the store, the associated password is updated to the
        /// value passed
        /// </summary>
        void StoreLoginInfo(string masterPassword, LoginInfo loginInfo, string password);

        /// <summary>
        /// Deletes an existing LoginInfo object
        /// </summary>
        void DeleteLoginInfo(string masterPassword, LoginInfo loginInfo);

        /// <summary>
        /// Returns a list of all the LoginInfo objects stored in the database
        /// </summary>
        IEnumerable<LoginInfo> LoginInfos();

        /// <summary>
        /// Returns the password associated with the given LoginInfo object
        /// </summary>
        string GetPassword(string masterPassword, LoginInfo loginInfo);

        /// <summary>
        /// Replaces the loginInfo object represented by oldLoginInfo with the newLoginInfo. This method
        /// can be used to change the url, loginid, or password
        /// </summary>
        void UpdateLoginInfo(string masterPassword,
                             LoginInfo loginInfo,
                             LoginInfo newLoginInfo,
                             string newPassword);

    }
}
